<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">	
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link rel="stylesheet" href="../../css/oksub.css">
	<script type="text/javascript" src="../../lib/loading/okLoading.js"></script>
	<style type="text/css">
	
	</style>
</head>
<body>
<div class="ok-body">
	<!--form表单-->
	<form class="layui-form layui-form-pane ok-form">
		<div class="layui-form-item">
			<label class="layui-form-label">名称</label>
			<div class="layui-input-block">
				<input type="text" id="FullName" name="FullName" autocomplete="off" class="layui-input"	 lay-verify="required">
			</div>	
		</div>	
		<div class="layui-form-item">
			<label class="layui-form-label">主管</label>
			<div class="layui-input-block">				
			
				<select  id="ManagerId" 	> </select>
			</div>	
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">排序</label>
			<div class="layui-input-block">
				<input type="text" id="SortCode" name="SortCode"  autocomplete="off" class="layui-input"	 lay-verify="required">
			</div>	
		</div>
		
	</form>
	
</div>
<!--js逻辑-->
<script src="../../lib/layui/layui.js"></script>
<script src="../../js/okform.js"></script>
<script>
     
    var ID = request("ID"); 
    var ManagerId = "";
    
    function AcceptClick() {
    	layui.use([ "okUtils"], function () {
    		let okUtils = layui.okUtils;
    		let $ = layui.jquery;
    		var saveCondition = {};
    		saveCondition['DepartmentId'] = ID;
    		saveCondition['FullName'] =encodeURI($("#FullName").val().trim());
    		saveCondition['SortCode'] = $("#SortCode").val();
    		saveCondition['ManagerId'] = $("#ManagerId").val();
    		var searchcondition = JSON.stringify(saveCondition)
    		
    		okUtils.ajax("DepartmentServlet?method=save", "get", {searchcondition: searchcondition}, true).done(function (response) {
				   console.log(response);
				  
				}).fail(function (error) {
					console.log(error)
				});
    	})
    
    }
    
    
	layui.use(["element", "form","jquery", "laydate", "okLayer", "okUtils", "okMock"], function () {
		let form = layui.form;
		let laydate = layui.laydate;
		let okLayer = layui.okLayer;
		let okUtils = layui.okUtils;
		let table = layui.table;
		let okMock = layui.okMock;
		let $ = layui.jquery;
		
		okLoading.close();		
		
		okUtils.ajax("UserServlet?method=getUserSelect", "get", null, true).done(function (response) {
			   var data =response.data;			 	
			  var txtconent = "<option value='0'>请选择</option>";
			  for(var i = 0; i < data.length; i ++){
				  txtconent = txtconent + "<option value='"+data[i].UserId+"'>"+data[i].RealName+"</option>"
			  }
			  $("#ManagerId").html(txtconent);
			  form.render();
			  if(ID){		 
					 okUtils.ajax("DepartmentServlet?method=getOneData", "get", {DepartmentId: ID}, true).done(function (response) {
						   var data =response.data;
						   ID = data.DepartmentId;			
						   $("#FullName").val(data.FullName);
						   $("#SortCode").val(data.SortCode);						  
						   $("#ManagerId").val(data.ManagerId);
						   form.render();
						}).fail(function (error) {
							console.log(error)
						});
				 }
			  
				
		}).fail(function (error) {
				console.log(error)
		});
			
	});
</script>
<!-- 行工具栏模板 -->
<script type="text/html" id="operationTpl">
	<a href="javascript:" title="编辑" lay-event="add"><i class="layui-icon">&#xe624;</i></a>
	<a href="javascript:" title="删除" lay-event="del"><i class="layui-icon">&#xe640;</i></a>
</script>
</body>
</html>
